var num = 1;
var answersum="";
var userid;
var question={
	    inintEvent: function(){
	        $("#bu2").unbind("click");
	        $("#bu2").bind("click", function(){
	        	
	        	if($("#bu2").val()=="下一题"||$("#bu2").val()=="完成答题"){
	        		userid = $("#userid").val();
	        		var sel ="";
	        		var select=$("input[name='selcet']");
	        		var b = sel.length;
	        		
	        		 for(var i=0;i<select.length;i++){
	        	         if(select[i].checked){
	        	        	 sel = sel + select[i].value+".";
	        	         }
	        		 } 
	        		 var a = sel.length;
	        		 if(a==b){
	        			 answersum = answersum + sel +".,";
	        		 }else{
	        			 answersum = answersum + sel +",";
	        		 }
	        	}
	        	$("#bu2").val("下一题");
	        	question.answer();
	        	if(num==10){	
	        		$("#bu2").val("完成答题");
	        	}
	        	if(num>10){
	        		$("#btn").hide();
	        		$("#bu2").hide();
	        	}
	           	num++;

	        });
	    },
		answer:function(){
			var parameter = {
				qid:num,
				answersum:answersum,
				userid:userid
			};
			$.post("questionJSONAction_getQuestion.do",parameter,function(data){
				$("#message").html(data);
			});	
		}
};
$().ready(function(){
	question.inintEvent();
	var x = 30,
    interval;
    window.onload = function() {
        var d = new Date("1111/1/1,0:" + x + ":0");
        interval = setInterval(function() {
            var m = d.getMinutes();
            var s = d.getSeconds();
            m = m < 10 ? "0" + m : m;
            s = s < 10 ? "0" + s : s;
            btn.innerHTML = "距离考试结束还有："+m + ":" + s;
            if (m == 0 && s == 0) {
                clearInterval(interval);
                btn.innerHTML = "考试结束";
                history.go(0);
                return;
            }
            d.setSeconds(s - 1);
        }, 1000);
    };
});